﻿/**
*创建名空间
*/
function createNameSpace(str) {
    var strs = str.split(".");
    var strT = strs[0];
    if (window[strT] == undefined) {
        window[strT] = new Object();
    }
    for (var i = 1; i < strs.length; i++) {
        if (eval(strT)[strs] == undefined) {
            eval(strT)[strs] = new Object();
        }
        strT += "." + strs;
    }
}
createNameSpace("safc");
function HashTable() {
    this.Items = [];
    this.Count = function() { return this.Items.length; };        //长度                 
    this.DictionaryEntry = function(key, value) {
        this.Key = key || null;
        this.Value = value || null;
    }
    this.Add = function(key, value) { this.Items.push(new this.DictionaryEntry(key, value)); }
    this.Clear = function() { this.Items.length = 0; }
    this.Remove = function(key) {
        var index = this.GetIndexWithKey(key);
        if (index > -1)
            this.Items.splice(index, 1);
    }
    this.GetItem = function(key) {
        var index = this.GetIndexWithKey(key);
        if (index > -1)
            return this.Items[index];
    }
    this.GetValue = function(key) {
        var index = this.GetIndexWithKey(key);
        if (index > -1)
            return this.Items[index].Value;
    }
    this.SetValue = function(key, value) {
        if (this.ContainsKey(key)) {
            this.Remove(key);
        }
        this.Items.push(new this.DictionaryEntry(key, value));
    }
    this.ContainsKey = function(key) {
        if (this.GetIndexWithKey(key) > -1)
            return true;
        return false;
    }
    this.ContainsValue = function(value) {
        if (this.GetIndexWithValue(value) > -1)
            return true;
        return false;
    }
    this.Keys = function() {
        var iLen = this.Count();
        var resultArr = [];
        for (var i = 0; i < iLen; i++)
            resultArr.push(this.Items[i].Key);
        return resultArr;
    }
    this.Values = function() {
        var iLen = this.Count();
        var resultArr = [];
        for (var i = 0; i < iLen; i++)
            resultArr.push(this.Items[i].Value);
        return resultArr;
    }
    this.IsEmpty = function() { return this.Count() == 0; }
    this.GetIndexWithKey = function(key) {
        var iLen = this.Count();
        for (var i = 0; i < iLen; i++)
            if (this.Items[i].Key === key)
            return i;
        return -1;
    }
    this.GetIndexWithValue = function(value) {
        var iLen = this.Count();
        for (var i = 0; i < iLen; i++)
            if (this.Items[i].Value === value)
            return i;
        return -1;
    }
}
//判断浏览器是否ie
function isIE() { //ie? 
    if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1)
        return true;
    else
        return false;
}
//限制文本框输入字符长度
function textlen(textarea, label, len) {
    try {
        if (textarea.value.length >= len)
            textarea.value = (textarea.value.substring(0, len))
        if (label != null)
            label.innerText = len - textarea.value.length;
    }
    catch (e) {
        alert('已到达最大长度！');
    }
}
//限制文本框输入中英文绝对字符长度
function textlenCN(textarea, len, label) {
    try {
        if (textarea.value.lengthCN >= len)
            textarea.value = (textarea.value.substring(0, len))
        if (label != null)
            label.innerText = len - textarea.value.lengthCN;
    }
    catch (e) {
        return false;
    }
}
//显示遮罩层
function showMask(page) {
    if (typeof (page) != 'object') {
        Mask = document.createElement("div");
        Mask.id = "MaskDiv";
        Mask.className = "DialogMask";
        document.body.appendChild(Mask);
        Mask.style.height = document.body.offsetHeight + "px";
    }
    else {
        Mask = page.createElement("div");
        Mask.id = "MaskDiv";
        Mask.className = "DialogMask";
        page.body.appendChild(Mask);
        Mask.style.height = parseInt(page.body.clientHeight) + parseInt(isIE() ? "0" : "40") + "px";
    }

}
//关闭遮罩层
function closeMask(page) {
    if (typeof (page) != 'object') {
        Mask = document.getElementById("MaskDiv");
        if (Mask) {
            Mask.style.display = "none";
            document.body.removeChild(Mask);
        }
    }
    else {
        Mask = page.getElementById("MaskDiv");
        if (Mask) {
            Mask.style.display = "none";
            page.body.removeChild(Mask);
        }
    }
}
//图片加载并按比例缩小到合适大小
//<img src=""  width="80" height="80" onload="DownImage(this,80,80,0,0);">
function DownImage(ImgD, MaxWidth, MaxHeight, alignX, alignY) {
    alignX = alignX || 1;
    alignY = alignY || 1;
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        var rate = (MaxWidth / image.width < MaxHeight / image.height) ? MaxWidth / image.width : MaxHeight / image.height;
        var wid = 0;
        var hid = 0;
        if (rate <= 1) {
            wid = ImgD.width = image.width * rate;
            hid = ImgD.height = image.height * rate;
        }
        else {
            wid = ImgD.width = image.width;
            hid = ImgD.height = image.height;
        }
        if (alignX == 1) {
            var ii = (MaxWidth - wid) / 2;
            ImgD.style.marginLeft = ImgD.style.marginRight = ii + "px";
        }
        if (alignY == 1) {
            var ii = (MaxHeight - hid) / 2;
            ImgD.style.marginTop = ImgD.style.marginBottom = ii + "px";
        }
    }
}
//图片加载并按比例缩小到合适大小
//<img src=""  width="80" onload="DownImage(this,80,0,0);">
function DownImageWidth(ImgD, MaxWidth, alignX, alignY) {
    alignX = alignX || 1;
    alignY = alignY || 1;
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        var rate = MaxWidth / image.width;
        var wid = 0;
        var hid = 0;
        if (rate <= 1) {
            wid = ImgD.width = image.width * rate;
            hid = ImgD.height = image.height * rate;
        }
        else {
            wid = ImgD.width = image.width;
            hid = ImgD.height = image.height;
        }
    }
}
function ShowWithElementoffsetXY(ElementId, WithElementId, offsetX, offsetY) {
    var elem = getAbsoluteLocation(document.getElementById(ElementId));
    var welem = document.getElementById(WithElementId);
    welem.style.left = (elem.absoluteLeft + offsetX) + "px";
    welem.style.top = (elem.absoluteTop + offsetY) + "px";
}

//attach(window,"load",function(){alert('111')})
function attach(o, e, f) {
    if (document.attachEvent)
        o.attachEvent("on" + e, f);
    else if (document.addEventListener)
        o.addEventListener(e, f);
}
//tabpanel面板
//     var divIds1=["001001003005001","001001003005002","001001003005003","001001003005004","001001003005005"];
//     var divIds2=["001001003006001","001001003006002","001001003006003","001001003006004"];
//<a id="span001001003005001" class="ac_span" href="javascript:displayDiv('001001003005001',divIds1,'ac_span','');"></a>
//<div id="div001001003005001"></div>
function tabpanels(Id, Ids, activeClass, normalClass) {
    for (var i = 0; i < Ids.length; i++) {
        if (Ids[i] == Id) {
            document.getElementById('div' + Id).style.display = 'block';
            document.getElementById('span' + Id).className = activeClass;
        }
        else {
            document.getElementById('div' + Ids[i]).style.display = 'none';
            document.getElementById('span' + Ids[i]).className = normalClass;
        }
    }
}
function tabpanelsint(Id, length, activeClass, normalClass) {
    for (var i = 1; i <= length; i++) {
        if (i == Id) {
            document.getElementById('div_' + Id).style.display = 'block';
            document.getElementById('span_' + Id).className = activeClass;
        }
        else {
            document.getElementById('div_' + i).style.display = 'none';
            document.getElementById('span_' + i).className = normalClass;
        }
    }
}
function tabdisplay(Id, Ids) {
    for (var i = 0; i < Ids.length; i++) {
        if (Ids[i] == Id) {
            document.getElementById('div' + Id).style.display = 'block';
            document.getElementById('span' + Id).style.display = 'none';
        }
        else {
            document.getElementById('div' + Ids[i]).style.display = 'none';
            document.getElementById('span' + Ids[i]).style.display = 'block';
        }
    }
}
function tabnodisplay(Id, Ids) {
    for (var i = 0; i < Ids.length; i++) {
        if (Ids[i] == Id) {
            document.getElementById('div' + Id).style.display = 'none';
            document.getElementById('span' + Id).style.display = 'block';
        }
        else {
            document.getElementById('div' + Ids[i]).style.display = 'none';
            document.getElementById('span' + Ids[i]).style.display = 'block';
        }
    }
}
function changeclass(Id, Class) {
    document.getElementById(Id).style.classname = Class;
}
